package cn.lg.soar.system.biz.modules.account.service;

import cn.lg.soar.common.util.current.CurrentProxy;
import cn.lg.soar.system.api.model.TokenInfoDTO;
import cn.lg.soar.system.biz.config.SsoClientProps;
import cn.lg.soar.system.biz.modules.account.model.SsoLoginDTO;
import cn.lg.soar.system.biz.modules.account.model.SsoNotifyClientLogout;
import cn.lg.soar.system.biz.modules.account.model.SsoUserBase;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;

/**
 * 单点登录客户端
 * @author luguoxiang
 * @date 2022/5/28
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
public interface ISsoClientService extends CurrentProxy<ISsoClientService> {

    /**
     * 获取token
     * @param serverId
     * @return
     */
    Config getConfig(String serverId);

    /**
     * 获取token
     * @return
     */
    default Config getConfig() {
        return proxy().getConfig("");
    }

    /**
     * 单点登录验证
     * @param serverId
     * @param ticket
     * @return
     */
    TokenInfoDTO validation(String serverId, String ticket);

    /**
     * 单点登录验证
     * @return
     */
    default TokenInfoDTO validation(SsoLoginDTO ssoLoginDTO) {
        return validation(ssoLoginDTO.getServerId(), ssoLoginDTO.getTicket());
    }

    /**
     * 单点登录退出
     * @param ssoLogout
     */
    void logout(SsoNotifyClientLogout ssoLogout);

    /**
     * 通知服务端用户下线
     * @param serverId
     * @param user
     */
    void notifyServerLogout(String serverId, SsoUserBase user);

    /**
     * 通知服务端用户下线
     * @param user
     */
    default void notifyServerLogout(SsoUserBase user) {
        notifyServerLogout(null, user);
    }

    @Getter
    @Setter
    class Config extends SsoClientProps.App {

        @Schema(description = "单点登录验证接口路径")
        private String validationUri;

        @Schema(description = "单点登出通知接口uri")
        private String logoutNotifyUri;

        @Schema(description = "下线接口路径")
        private String offlineUri;

        @Schema(description = "访问token")
        private String ssoToken;

    }
}
